<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="${path}/static/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${path}/static/css/font-awesome.min.css">
    <link rel="stylesheet" href="${path}/static/css/main.css">
    <style>
        .tree li {
            list-style-type: none;
            cursor:pointer;
        }
        table tbody tr:nth-child(odd){background:#F4F4F4;}
        table tbody td:nth-child(even){color:#C00;}
    </style>
</head>

<body>

<%-- 顶部导航 --%>
<jsp:include page="${path}/static/nav.jsp"></jsp:include>

<div class="container-fluid">
    <div class="row">

        <%--  左侧导航栏  --%>
        <jsp:include page="${path}/static/left.jsp"></jsp:include>

        <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title"><i class="glyphicon glyphicon-th"></i> 数据列表</h3>
                </div>
                <div class="panel-body">
                    <form class="form-inline" role="form" style="float:left;">
                        <div class="form-group has-feedback">
                            <div class="input-group">
                                <div class="input-group-addon">查询条件</div>
                                <input id="select" class="form-control has-success" type="text" placeholder="请输入查询条件">
                            </div>
                        </div>
                        <button onclick="like()" type="button" class="btn btn-warning"><i class="glyphicon glyphicon-search"></i> 查询</button>
                    </form>
                    <button type="button" class="btn btn-danger" style="float:right;margin-left:10px;"><i class=" glyphicon glyphicon-remove"></i> 删除</button>
                    <button type="button" class="btn btn-primary" style="float:right;" onclick="window.location.href='form.html'"><i class="glyphicon glyphicon-plus"></i> 新增</button>
                    <br>
                    <hr style="clear:both;">
                    <div class="table-responsive">
                        <table class="table  table-bordered">
                            <thead>
                            <tr >
                                <th width="30">#</th>
                                <th width="30"><input type="checkbox"></th>
                                <th>名称</th>
                                <th width="100">操作</th>
                            </tr>
                            </thead>
                            <tbody id="bodyData">

                            </tbody>
                            <tfoot>
                            <tr >
                                <td colspan="6" align="center">
                                    <ul class="pagination" id="pageData">

                                    </ul>
                                </td>
                            </tr>

                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="${path}/static/jquery/jquery-2.1.1.min.js"></script>
<script src="${path}/static/bootstrap/js/bootstrap.min.js"></script>
<script src="${path}/static/script/docs.min.js"></script>
<script src="${path}/static/layer/layer.js"></script>
<script type="text/javascript">
    $(function () {
        $(".list-group-item").click(function(){
            if ( $(this).find("ul") ) {
                $(this).toggleClass("tree-closed");
                if ( $(this).hasClass("tree-closed") ) {
                    $("ul", this).hide("fast");
                } else {
                    $("ul", this).show("fast");
                }
            }
        });

        showList(1);

    });
    $("tbody .btn-success").click(function(){
        window.location.href = "assignPermission.html";
    });

    function like(){
        showList(1);
    }

    function showList(pageNum){
        var selectStr = $("#select").val();
        $.ajax({
            url:"${path}/role/list",
            method:"post",
            data:{"pageNum":pageNum,"like":selectStr},
            datatype:"json",
            error:function (err) {
                alert("失败")
            },
            success:function (obj) {
                var bodyHtml = "";
                $.each(obj.roleList,function (index,role) {
                    bodyHtml += '<tr>';
                    bodyHtml += '<td>'+(index+1)+'</td>';
                    bodyHtml += '<td><input type="checkbox" value="'+role.roleid+'"></td>';
                    bodyHtml += '<td>'+role.rolename+'</td>';
                    bodyHtml += '<td>';
                    bodyHtml += '<button type="button" class="btn btn-success btn-xs" onclick="rolePermission('+role.roleid+')" ><i class=" glyphicon glyphicon-check"></i></button>';
                    bodyHtml += '<button type="button" class="btn btn-primary btn-xs"><i class=" glyphicon glyphicon-pencil"></i></button>';
                    bodyHtml += '<button type="button" class="btn btn-danger btn-xs"><i class=" glyphicon glyphicon-remove"></i></button>';
                    bodyHtml += '</td>';
                    bodyHtml += '</tr>';
                });
                $("#bodyData").html(bodyHtml);

                var pageHtml = "";
                pageHtml += "<li class='"+(obj.pageInfo.pageNum==1?'disabled':'')+"'><a onclick='showList("+1+")' >首页</a></li>";
                pageHtml += "<li class='"+(obj.pageInfo.pageNum==1?'disabled':'')+"'><a onclick='showList("+obj.pageInfo.perPage+")' >上一页</a></li>";
                for(var i = 1; i <= obj.pageInfo.pages ; i++){
                    pageHtml +="<li class='"+(obj.pageInfo.pageNum==i?'active':'')+"'><a onclick='showList("+i+")'>"+i+" <span class='sr-only'>(current)</span></a></li>";
                }
                pageHtml += "<li class='"+(obj.pageInfo.pageNum==obj.pageInfo.pages?'disabled':'')+"'><a onclick='showList("+(obj.pageInfo.pageNum==obj.pageInfo.pages?obj.pageInfo.pages:obj.pageInfo.nextPage)+")' >下一页</a></li>";
                pageHtml += "<li class='"+(obj.pageInfo.pageNum==obj.pageInfo.pages?'disabled':'')+"'><a onclick='showList("+obj.pageInfo.pages+")' >末页</a></li>";
                $("#pageData").html(pageHtml);
            }
        });
    }

    function rolePermission(roleid) {
        alert(roleid);
        location.href = "${path}/rolepermission/index";
    }



</script>
</body>
</html>
